package com.cbg.es.service.impl;

import com.cbg.es.entity.EsCategory;
import com.cbg.es.repository.IEsCategoryRepository;
import com.cbg.es.service.IEsCategoryService;
import com.shuyuwl.core.enums.StatusEnum;
import com.shuyuwl.core.exception.SymServiceException;
import com.shuyuwl.core.service.impl.DaoServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 全景通查分类 serviceImpl
 *
 * @author wangjuzheng
 * @since 2019-10-16
 */
@Service
@Transactional(rollbackFor = SymServiceException.class)
public class EsCategoryServiceImpl extends DaoServiceImpl<EsCategory, Long, IEsCategoryRepository> implements IEsCategoryService {

    @Resource
    private IEsCategoryRepository esCategoryRepository;

    @Override
    public List<EsCategory> findCategory(Byte status) {
        return esCategoryRepository.findByStatusOrderBySortAsc(status);
    }

    @Override
    public List<EsCategory> findByPid(Long id, Byte status) {
        return esCategoryRepository.findByPidAndStatusOrderBySortAsc(id, status);
    }

    @Override
    public EsCategory findByIdAndStatus(Long id, Byte status) {
        return esCategoryRepository.findByIdAndStatus(id, status);
    }

    @Override
    public Integer getMaxSort(Long pid, Byte status) {
        return esCategoryRepository.getMaxSort(pid, status);
    }

    @Override
    public List<EsCategory> findByPidAndCategoryName(Long categoryPid, String categoryName) {
        return esCategoryRepository.findByPidAndNameAndStatus(categoryPid,categoryName, StatusEnum.OK.getCode());
    }
}
